#pragma once
#include <thread>
#include <mutex>
#include <deque>
#include <string>
#include "NetSock.h"
#include "macros.h"
#include "packets.h"


class cConnection {
public:
	bool Closed;

	cConnection( NetSock* );
	cConnection( cConnection const & ) { ASSERT(0); }
	~cConnection();

	std::string GetSocketString();
	bool QueuePacket( cPacketBase* );
	void ClearQueue();

	unsigned char readByte();
	unsigned short readShort();
	unsigned int readInt();
	std::string readString();

private:
	NetSock* _socket;
	std::thread* _thread;
	std::deque<cPacketBase*> packetQueue;
	std::mutex queueMutex;
	
	std::string loginSalt;
	std::string fullname;
	std::string username;
	long long teacherid;
	long long userid;
	int accessgroup;
	bool loggedIn;
	bool chatAccess;
	long long sessionStart;

	void doCleanup();

	static void threadfunc( cConnection* );
};
